﻿@section header
{<!-- Bellows Styles -->
    <link href="~/Themes/RongJi/Style/base/css/limit.css?v=2" rel="stylesheet" />
    <style>
        .pageHeaderMini {
            display: none;
        }
    </style>
}
@section title
{
    蓉记鲜秒客，优品任性GO
}
@section pagetitle
{
    蓉记鲜秒客，优品任性GO
}
@using Kevin.Shop.Business.Service.Entity.Helper
@model RiderShop.Mobile.Modle.Product.ProductListModel
<div class="toolbar">
    <a href="javascript:window.history.go(-1)" class="goback">返回</a>
    <a href="http://m.rongji365.com/" class="gohome">首页</a>
</div>
<ul id="tabs">
    <li class="current">鲜秒客</li>
    <li>即将上线</li>
</ul>
<div class="limit-container">
    <div class="limit-wrapper">
        <div data-role="container" class="product-container glist">
            <input type="hidden" value="1" id="pageIndex">
            <section data-role="body" class="body">
                @if (Model.Result.Data.Count == 0)
                {
                    <div class="noresult">
                        <div class="inner-wrapper">
                            <h1>十分抱歉，暂时没有参与的促销商品</h1>
                        </div>
                    </div>
                }
                else
                {
                    <input type="hidden" id="currentUserId" value="@WebClientContext.Current.UserId">
                    <div>
                        <ul id="produt_list" class="glist_ul glist_grid glist_big"></ul>
                        <div data-role="widget" data-widget="loading_bottom" id="loading_bottom" class="loading_bottom" style="display: none">
                            <div class="widget_wrap">
                                <ul class="tbox">
                                    <li>
                                        <div class="loading_wrap">
                                            <span class="loading">&nbsp;</span>
                                        </div>
                                    </li>
                                    <li>
                                        正在加载，请稍后...
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <div id="showMore" page="0">
                        </div>
                    </div>
                }
            </section>
        </div>
    </div>
</div>





@section footer
{


    <script src="~/Themes/RongJi/Style/plugins/spin.min.js"></script>
    <script language="javascript" type="text/javascript">
        var scrollSeleep = false;

        var url = "SpecialPriceProduct?";
        var urlAjax = "SpecialPriceProductByAjaxRequest?";

        //添加到购物车
        var AddToCart = function(productId, quantity) {
            try {
                KevinShop.Common.ShoppingCart.UpdateToCart(productId, quantity);
                KevinShop.MessageBox.Success("添加到购物车成功！");
                //添加购物车成功后,篮子变成绿色且上面的数字发生变化
                KevinShop.Common.ShoppingCart.RefreshTotalQty();
                var total = KevinShop.Common.ShoppingCart.TotalQty;
                if (total > 0) {
                    $('.cart_badge img').attr('src', '/Themes/RongJi/Style/base/imgs/shopcart_full.png');
                    $(".cart_badge .badge").html(total);
                } else {
                    $('.cart_badge img').attr('src', '/Themes/RongJi/Style/base/imgs/shopcart_empty.png');
                    $(".cart_badge .badge").html("");
                }
            } catch(e) {
                console.log(e);
            }
        };


        var ReminderMe = function(productId, endDate,productName) {

            window.location.href = "ReminderMe?ProductId="+productId+"&NotifyDate="+escape(endDate)+'&ProductName='+escape(productName);
            return false;
        };

        //滚动到屏幕底部时,追加下一页数据
        /*---------------------加载更多--------------------*/
        var isloading = false;
        var counter = 1;
        var totalPage = @Model.TotalPage;
        var lastDate = new Date('1900/01/01');
        if(totalPage > 1) {
            $(window).bind("scroll", function() {
                if(scrollSeleep)
                {
                    return;
                }
                if ($(document).scrollTop() + $(window).height() + 10 >= $(document).height()) {
                    LoadProduct(totalPage);
                }
            });
        }

        function LoadProduct(totalPage){
            var pageIndex = $('#showMore').attr('page');
            var args = "";
            if(totalPage > 0 && pageIndex >= totalPage) {
                $("#showMore").show().html('加载完毕').delay(2300).slideUp(1600);
                return;
            }
            if(isloading) {
                return;
            }
            $("#loading_bottom").show();
            isloading = true;
            args = "pageIndex=" +  pageIndex;
            $.ajax({
                type: "GET",
                url:  urlAjax + args,
                dataType: "JSON",
                success: function(response){
                    isloading = false;
                    if(response.length){
                        $('#showMore').attr('page',parseInt(pageIndex)+1);
                    }
                    $("#loading_bottom").hide();


                    if(response.length){
                        response.sort(function(a,b){return b.BeginDate > a.BeginDate ? 1 : -1;});
                    }

                    /*---------------------半透明慢慢的滑动上来,在向上滑动过程中越来越明显--------------------*/
                    $.each(response, function(key, value) {
                        var beginDate = new Date(value.BeginDateFormat);
                        if(lastDate.toDateString()!==beginDate.toDateString()){
                            lastDate = beginDate;
                            $("#produt_list").append('<li class="date"><h2><span class="glyphicon glyphicon-certificate"></span>&nbsp;'+lastDate.getFullYear()+'/'+(lastDate.getMonth()+1)+'/'+lastDate.getDate()+'</h2></li>');
                        }

                        if(beginDate.toDateString()===(new Date()).toDateString()){
                            $("#produt_list").append("<li class='red' id='div" + counter + "' style='margin-top:80px;opacity:0.3'></li>");
                        }
                        else{
                            if(beginDate<new Date()){
                                $("#produt_list").append("<li class='blue' id='div" + counter + "' style='margin-top:80px;opacity:0.3'></li>");
                            }
                            else{
                                $("#produt_list").append("<li class='yellow' id='div" + counter + "' style='margin-top:80px;opacity:0.3'></li>");
                            }
                        }

                        var promoIcon = '';

                        var html = '<a href="/Product/ProductDetail?prd=' + value.ProductId + '">'
                            + promoIcon
                            + ' <span class="save-money">省<em>' + (value.MarketPrice - value.UnitPrice).toFixed(2) + '</em></span>'
                            + '   <div>'
                            + '         <span class="img_wrap" >'
                            + '             <img src="http://m.rongji365.com/Storage/limit/' + value.ProductId + '.jpg">'
                            + '          </span>'
                            + ' <div class="ttt">'
                            + ' <div class="left-ttt"><h2>' + value.ProductName + '<em>' + value.PromotionDescription + '</em></h2>'
                            + '<h3>￥' + value.UnitPrice + '<em>￥'
                            + value.MarketPrice.toFixed(2)
                            + '</em></h3></div>';

                        //    + ' <div class="buyers">已有';
                        //if(value.TotalInventory > 0){
                        //    html += Math.abs(value.PromotionStock - value.TotalInventory);
                        //}
                        //else {
                        //    html += Math.abs(value.TotalInventory);
                        //}
                        ////html += '人购买 剩' + value.TotalInventory + '件</div><p>';
                        //html += '人购买</div><p>';

                        if(value.PromotionStatus == 2) {
                            if (value.TotalInventory > 0)
                            {
                                html   =html + '  <div class="right-ttt"><div class="timers"><span class="orange lxftime" endtime="' + value.EndDateFormat + '">'
                                                + '  <span>1</span> 天 <span>0</span> : <span>0</span> : <span>0</span> : </span></div>';
                                if (value.Active) {
                                    html += '<span class="lbtn i-want-it" onclick="AddToCart(\'' + value.ProductId + '\',1);return false;">我要抢</span>';
                                } else {
                                    html += '<span class="lbtn disabled-btn" onclick="return false;">还没上架</span>';
                                }
                            }
                            else
                            {
                                html += '<div class="right-ttt"><div class="timers">&nbsp;</div>'
                                html += '<span class="lbtn disabled-btn" onclick="return false;">卖光了</span>';
                            }
                        } else if(value.PromotionStatus == 1) {
                            var datestr = value.BeginDateFormat.length > 16 ?  value.BeginDateFormat.substring(9,value.BeginDateFormat.length) :value.BeginDateFormat;
                            html += '<div class="right-ttt"><div class="timers">' + datestr + ' 准时抢</div>'
                            //   html += '<span class="lbtn disabled-btn" onclick="return false;">抢购未开始</span>';
                            html += '<span class="lbtn i-want-it" onclick="ReminderMe(\'' + value.ProductId + '\',\'' + value.BeginDateFormat + '\',\'' + value.ProductName +  '\');return false;">提醒我</span>';
                        }
                        else if(value.PromotionStatus == 3) {
                            html += '<div class="right-ttt"><div class="timers">&nbsp;</div>'
                            html += '<span class="lbtn disabled-btn" onclick="return false;">抢购已结束</span>';
                        }

                        html +='</p></div></div></div></a>';
                        $("#div" + counter).append(html).animate({ opacity: '1', marginTop: 0 }, 1200);
                        counter++;
                    });
                },
                error:function(response){
                    alert('1');
                }
            });
        }


        $(document).ready(function() {

            var _w = $('.toolbar').width() - 92;

            $('#tabs').css({
                width: _w + 'px'
            });
            //设置section位置为一屏
            $('*[data-role="body"]').css("min-height", (Math.min(window.screen.height, (document.body.scrollHeight-80)) - $('*[data-role="header"]').height() )+"px");
            KevinShop.Common.TimePick();

            LoadProduct(totalPage);

            //让底部toolbar选中
            var $homeImg = $("#homeImg");
            var $categoryImg = $("#categoryImg");
            var $myaccountImg = $("#myaccountImg");
            var $searchImg = $("#searchImg");
            $homeImg.attr("src", "/Themes/RongJi/Style/base/imgs/f10.png");
            $categoryImg.attr("src", "/Themes/RongJi/Style/base/imgs/f2.png");
            $myaccountImg.attr("src", "/Themes/RongJi/Style/base/imgs/f3.png");
            $searchImg.attr("src", "/Themes/RongJi/Style/base/imgs/f4_c.png");

            //当只有一页数据时'更多'不需要显示出来
            if(@Model.TotalPage == 1) {
                $("#showMore").hide();
            }
        });


        window.config = {
            link: window.location.href,
            imgUrl: 'http://m.rongji365.com/Themes/RongJi/Style/base/imgs/miao.jpg',
            img_url: 'http://m.rongji365.com/Themes/RongJi/Style/base/imgs/miao.jpg',
            title: document.title,
            desc: "手慢了，真的就没有了！"
        };
    </script>
}
